package org.etherframework.tests.features.wiring
{
	import org.etherframework.common.wire.IWiring;
	import org.etherframework.core.IModule;
	import org.etherframework.tests.features.wiring.processors.Hello;
	import org.etherframework.tests.features.wiring.processors.NotAProcessor;
	import org.etherframework.tests.utils.TestUtility;
	import org.etherframework.wire.ProcessorFactory;
	import org.hamcrest.assertThat;
	import org.hamcrest.object.equalTo;
	import org.hamcrest.object.notNullValue;

	public class when_adding_processor
	{	
		private static var _testUtility:TestUtility = new TestUtility();
		private static var _module:IModule;
		private static var _w:IWiring;
		
		[BeforeClass]
		public static function setUpBeforeClass():void
		{
			_module = _testUtility.createModule();
			_w = _module.wiring;
			
			_w.addProcessor(new ProcessorFactory(Hello));
		}
		
		[AfterClass]
		public static function tearDownAfterClass():void
		{
			_testUtility.dispose();
		}
		
		[Test(order=1)]
		public function it_should_be_added():void
		{
			var processor:Class = _w.hasProcessor(Hello.NAME);
			assertThat(processor, notNullValue());
			assertThat(processor, equalTo(Hello));
		}
		
		[Test(order=2)]
		public function it_should_throw_an_error_when_arguments_are_not_valid():void
		{
			var err:Error;
			
			try {
				_w.addProcessor(new ProcessorFactory(NotAProcessor));
			} catch (e:*) {err = e;}
			assertThat(err, notNullValue());
			err = null;
			
			try {
				_w.addProcessor(new ProcessorFactory(null, Hello.NAME));
			} catch (e:*) {err = e;}
			assertThat(err, notNullValue());
			err = null;
		}
		
		[Test(order=3)]
		public function it_should_throw_an_error_when_processor_is_already_added():void
		{
			var err:Error;
			
			try {
				_w.addProcessor(new ProcessorFactory(Hello));
			} catch (e:*) {err = e;}
			assertThat(err, notNullValue());
			err = null;
		}
	}
}